<template>
  <div>
    <div class="mv">
      <video :src="video" controls></video>
      <span class="iconfont icon-xiangzuo" @click="retn"></span>
    </div>
    <div class="pinlun">
      <div class="topSection">
        <div :class="[{ selects: flag }]" @click.stop="leftsDetails">详情</div>
        <div :class="[{ selects: !flag }]" @click.stop="rightsComments">
          全部评论（{{ comments.length }}）
        </div>
      </div>
      <!-- 详情内容 -->
      <div class="details" ref="content" v-show="flag">
        <div class="topList">最新热门MV推荐</div>
        <ul class="tuijian">
          <li v-for="(key, i) in list" :key="i">
            <!-- <video src=""></video> -->
            <img :src="key.picUrl" alt="" @click="gotoPlay(key.id, key.name)" />
            <div>
              <p>{{ key.name }}</p>
              <p>{{ key.artistName }}</p>
            </div>
          </li>
        </ul>
      </div>
      <!-- 评论内容 -->
      <div class="content" ref="content" v-show="!flag">
        <ul>
          <li v-for="(item, index) in comments" :key="index">
            <div class="titles">
              <img :src="item.user.avatarUrl" alt="" />
              <span>{{ item.user.nickname }}</span>
              <!-- <span
                @click.stop="getreSourceLikeFn(index)"
                :class="['iconfont', 'icon-dianzan', { record: item.flag }]"
              ></span> -->
            </div>
            <div class="looks">{{ item.content }}</div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import { getCommentMv, getMvUrl, getrePersonalized } from "../api/mv.js";
import BScroll from "@better-scroll/core";

export default {
  data() {
    return {
      comments: [],
      hotComments: [],
      list: [],
      video: null,
      flag: true,
      look: true,
      offset: 0,
      title: null,
      indexs: null,
      flag2: false,
    };
  },
  methods: {
    // 滚动效果初始化方法
    _initScroll(dom, flagx, flagy) {
      // 右侧滚动效果初始化
      this.rights = new BScroll(dom, {
        click: true, //点击触发
        probeType: 3, //深针的效果，时时获取滚动高度
        scrollX: flagx,
        scrollY: flagy,
      });
    },
    // 视频接口
    getMvUrlFn(id) {
      getMvUrl({ id }).then((data) => {
        this.video = data.data.url;
        console.log("图", data);
        // 数据没有通过视图
      });
    },
    // 评论接口
    getCommentMvFn(id) {
      getCommentMv({ id }).then((data) => {
        this.comments = data.comments;
        this.comments.forEach((item) => {
          item.flag = false;
        });
        console.log("评论", this.comments);
      });
    },
    // 推荐视频播放
    gotoPlay(id, item) {
      this.getMvUrlFn(id);
      this.getCommentMvFn(id);
      this.title = item;
    },
    // 点赞功能
    getreSourceLikeFn(index) {
      this.flag2 = !this.flag2;
      console.log(this.comments[index].flag);
      // this.comments[index].flag = this.flag2;
      console.log(this.comments[index].flag);
      // 数据没有通过视图
      this.$set(this.mvList[index], "flag", this.flag2);
      console.log(this.comments);
    },
    // 点击返回上一个界面
    retn() {
      this.$router.go(-1);
    },
    // 点击详情显示
    leftsDetails() {
      this.flag = true;
    },
    // 点击评论显示
    rightsComments() {
      this.flag = false;
    },
    // 文字显示
    viewAll() {
      this.look = !this.look;
    },
  },
  mounted() {
    this.$nextTick(() => {
      setTimeout(() => {
        this._initScroll(this.$refs.content, false, true);
      }, 3000);
    });
  },
  created() {
    this.title = this.$route.query.name;
    // 视频接口
    this.getMvUrlFn(this.$route.query.id);
    // 评论接口
    this.getCommentMvFn(this.$route.query.id);
    // 视频列表接口
    getrePersonalized().then((data) => {
      this.list = data.result;
      console.log("mvid", this.list);
    });
  },
};
</script>

<style lang="less" scoped>
.mv {
  width: 100%;
  background: pink;
  position: relative;
  video {
    // min-width: 320px;
    // max-width: 750px;
    height: 211px;
    margin: 0 auto;
    display: block;
  }
  .iconfont {
    width: 30px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    position: absolute;
    top: 6px;
    left: 0;
    color: #fff;
    font-size: 20px;
  }
}
.pinlun {
  .topSection {
    width: 100%;
    height: 50px;
    line-height: 45px;
    background: #eee;
    padding: 10px;
    box-sizing: border-box;
    font-size: 18px;
    color: #333;
    display: flex;
    align-items: center;
    div {
      flex: 1;
      text-align: center;
      &.selects {
        color: #d4473c;
        font-weight: 700;
      }
    }
  }
  .content {
    width: 100%;
    //   height: 100%;
    position: absolute;
    top: 271px;
    bottom: 0;
    overflow: hidden;

    ul {
      li {
        width: 100%;
        padding: 10px;
        box-sizing: border-box;

        box-sizing: border-box;
        box-sizing: border-box;
        font-size: 16px;

        .titles {
          // width: 100%;
          display: flex;
          align-items: center;
          position: relative;
          img {
            height: 40px;
            width: 40px;
            border-radius: 50%;
            background: pink;
            margin-right: 12px;
          }
          span {
            color: #1a73e8;
            font-weight: 700;
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
            // &:nth-child(3) {
            //   color: #000;
            //   position: absolute;
            //   top: 50%;
            //   right: 0;
            //   transform: translateY(-50%);
            //   font-size: 18px;
            // }
            &.record {
              color: #d4473c;
              font-size: 18px;
            }
          }
        }
        .looks {
          margin-top: 10px;
          margin-left: 52px;
          color: #5a5a5a;
        }
      }
    }
  }
  .details {
    padding: 10px;
   
    .topList {
      height: 40px;
      line-height: 40px;
      // background: #eee;
      font-size: 16px;
      // font-weight: 700;
      color: #333;
    }
    .tuijian {
      li {
        display: flex;
        margin: 10px 0;
        box-sizing: border-box;

        img {
          width: 30%;
          // height: 60px;
          background: pink;
          border-radius: 12px;
          margin-right: 10px;
        }
        div {
          padding: 5px 0;
          box-sizing: border-box;
          overflow: hidden;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          p {
            &:nth-child(1) {
              display: block;
              font-size: 18px;
              color: #333;
              overflow: hidden;
              box-sizing: border-box;
              text-overflow: ellipsis;
              white-space: nowrap;
            }
            &:nth-child(2) {
              font-size: 16px;
              color: #ccc;
              overflow: hidden;
              box-sizing: border-box;
              text-overflow: ellipsis;
              white-space: nowrap;
            }
          }
        }
      }
    }
  }
}
</style>